package cn.tx.redislock.mylock;

import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.locks.Lock;

/**
 * @author jizenan
 * @date 2025/6/10
 * Description:
 */
@Component
public class DistributedLockFactory {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private String lockName;
    private String uuid;

    public DistributedLockFactory() {
        this.uuid = IdUtil.simpleUUID();
    }

    public Lock getDistributedLock(String type){
        if(type.equalsIgnoreCase("REDIS")){
            this.lockName = "zzyyRedisLock";
            return new RedisDistributedLock(stringRedisTemplate,lockName,uuid);
        }else if(type.equalsIgnoreCase("ZOOKEEPER")){
            //TODO zookeeper版本分布式锁实现
        }else if(type.equalsIgnoreCase("MYSQL")){
            //TODO MYSQL版本分布式锁实现
        }
        return null;
    }
}
